Page 81 - 2629_Devagiri_C-8
P. 81

INSERTING DATA TO SPECIFIC COLUMN  The SELECT command can also retrieve specific
 To insert data into specific columns, list only those columns in the INSERT statement. The remaining   fields from a table by listing the column names

 columns will be set to their default values or left NULL.  instead of using the asterisk (*).
 The syntax for inserting into specific columns is as follows:   For example, to  display  only  the  StudentID  and
                 FirstName from the Students table, use the given
 INSERT INTO table_name (column1, column2, ...)
                 command.
 VALUES (value1, value2, ...);
 The command to insert data into specific columns of a table is as follows:




                                   If  a database is like  a treasure  chest  and you’re  the treasure  keeper,  how would
                                   you organise and store your precious items to make sure you can find them easily
                                   when needed?


                 THE WHERE CLAUSE

                 The SELECT command supports several optional clauses to refine your results. The WHERE clause
 RETRIEVING DATA FROM TABLE  is one of the most useful, as it filters records based on specified conditions.
                 The syntax of the WHERE clause is as follows:
 Retrieving data from a table involves using commands to fetch specific or all records stored in it.
 This helps in viewing and analysing the required information easily.  SELECT * FROM  table_name WHERE condition;
                 For example, to retrieve the records of all students with the last name ‘Sharma’, use the following
 THE SELECT COMMAND  SELECT command:

 The SELECT command retrieves zero or more rows from a table. It used to join information from

 different tables and filter specific information as per the required criteria.
 The syntax to use the SELECT command as follows:

 SELECT * FROM table_name;
 Where, * is used to select all the columns of the specified table.

 To display all the data in the table, the SELECT command will be as follows:
                 For example, to find students older than 15 and show their StudentID, FirstName, and Age, use the
                 following SELECT command:

















                 In SQL, you can retrieve data based on multiple conditions by using the AND and OR operators.
                 These operators allow you to combine more than one condition through the WHERE clause.




                                                                                                                  79
                                                                                          MySQL: My First Database
   76   77   78   79   80   81   82   83   84   85   86